/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * insumos_entradas_agregar.java
 *
 * Created on 15/06/2011, 08:01:35 PM
 */

package sie_invdis;

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

import java.text.ParseException;

/**
 *
 * @author Michelle
 */
public class insumos_entradas_agregar extends javax.swing.JDialog {

    private javax.swing.table.DefaultTableModel jtable_modelo;
    private bd_conexion x = new bd_conexion() ;
       //se creaa la variable resultset
    private ResultSet rs = null;
    int controlcombo=0;

    /** Creates new form insumos_entradas_agregar */
    public insumos_entradas_agregar(java.awt.Frame parent, boolean modal) {
         super(parent, modal);
         this.iniciar_modelo_de_tabla();
        initComponents();
         java.util.Date fechahoya=new Date();

        this.jdc_fechadocto.setDate(fechahoya);
        this.jdc_fecharecepcion.setDate(fechahoya);
        this.loadcombo();
        this.loadcomalmacenes();
        this.loadcombotipos();

         controlcombo=1;

        jtb_insumos.getColumnModel().getColumn(0).setPreferredWidth(60);//status
        jtb_insumos.getColumnModel().getColumn(1).setPreferredWidth(160);//Folio
        jtb_insumos.getColumnModel().getColumn(2).setPreferredWidth(30);//status
        jtb_insumos.getColumnModel().getColumn(3).setPreferredWidth(30);//doc ant.
        jtb_insumos.getColumnModel().getColumn(4).setPreferredWidth(30);//fecha
        jtb_insumos.getColumnModel().getColumn(5).setPreferredWidth(30);//fecha llega tienda
        jtb_insumos.getColumnModel().getColumn(6).setPreferredWidth(30);//f.recepcion
        jtb_insumos.getColumnModel().getColumn(7).setPreferredWidth(30);//f.recepcion
        jtb_insumos.getColumnModel().getColumn(8).setPreferredWidth(80);//f.recepcion
        this.jtf_docto.requestFocus();

    }

private void iniciar_modelo_de_tabla()
    {
        jtable_modelo=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modelo.addColumn("<html><b>Clave</b></html>");
        jtable_modelo.addColumn("<html><b>Descripcion</b></html>");
        jtable_modelo.addColumn("<html><b>Unidad</b></html>");
        jtable_modelo.addColumn("<html><b>Cantidad</b></html>");
        jtable_modelo.addColumn("<html><b>Costo</b></html>");
        jtable_modelo.addColumn("<html><b>Desc.</b></html>");
        jtable_modelo.addColumn("<html><b>I.v.a.</b></html>");
        jtable_modelo.addColumn("<html><b>Importe.</b></html>");
        jtable_modelo.addColumn("<html><b>Observaciones</b></html>");
    }
private void loadcombo()
{
       
       this.jcmbx_tiendaclie.addItem("0"+":"+"ELEGIR PROVEEDOR");
       try
         {
              rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_entradas_proveedores(0) as (idprov character varying(12),provedescribe character varying(60));",variables_global.getconexiongral());
            while (rs.next())
                {
                            this.jcmbx_tiendaclie.addItem(rs.getString("idprov")+":"+rs.getString("provedescribe"));
                }

        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
}

private void cargar_insumos(int tipo_elemento)
    {
        this.LimpiarJTable();

       try
         {
         rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_catalogo(1,0,'"+tipo_elemento+"') as (cla character varying(16),des character varying(80), unsal character varying(3),descritipo character varying(40),orden numeric);",variables_global.getconexiongral());
            while (rs.next())
                {
                    jtable_modelo.addRow(new Object[]{rs.getString ("cla"),rs.getString ("des"),rs.getString("unsal"),0,0,this.jtf_descuento.getText(),this.jtf_impuesto.getText(),0,"."});
                }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
private void LimpiarJTable()
 {
     //limpiar la tabla
    while(jtable_modelo.getRowCount()>0)jtable_modelo.removeRow(0);
 }
private void loadcomalmacenes(){
          this.jcmbx_almacenes.addItem(variables_global.getalmacen()+":"+variables_global.getalmacen());
          rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_almacenes() as (id smallint,cla character varying(30));",variables_global.getconexiongral());
            try
            {
               while (rs.next())
                    {
                      this.jcmbx_almacenes.addItem(rs.getString("id")+":"+rs.getString("cla"));
                    }
             }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
}

private void loadcombotipos(){
       rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_tipos() as (id smallint,cla character varying(40));",variables_global.getconexiongral());
       this.jcbx_tiposinsumos.addItem("0"+":"+"Elegir Tipo Insumo");
       try
         {
            while (rs.next())
                {
                            this.jcbx_tiposinsumos.addItem(rs.getString("id")+":"+rs.getString("cla"));
                }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
}
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpn_encabezado = new javax.swing.JPanel();
        jcbx_tiposinsumos = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jtf_observaciones = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jdc_fechadocto = new com.toedter.calendar.JDateChooser();
        jcmbx_tiendaclie = new javax.swing.JComboBox();
        jcmbx_almacenes = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jcb_verfotos = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jtf_docto = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtf_descuento = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jdc_fecharecepcion = new com.toedter.calendar.JDateChooser();
        jLabel9 = new javax.swing.JLabel();
        jtf_impuesto = new javax.swing.JTextField();
        jpn_cuerpo = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtb_insumos = new javax.swing.JTable()
        //{
            //  public boolean isCellEditable(int rowIndex, int mColIndex) {
                //    if (mColIndex < 3)
                //  return false;
                //else
                //return true;
                //}
            //}
        ;
        jLabel10 = new javax.swing.JLabel();
        jtf_doctosubtotal = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jtf_doctodesc = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jtf_doctoimp = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jtf_doctototal = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jtf_totalpiezas = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jbtn_guardar = new javax.swing.JButton();
        jbtn_salir = new javax.swing.JButton();
        jbtn_helpayudame = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jtf_idinsumo = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jtf_insumodescripcion = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jtf_item = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jtf_unidadsal = new javax.swing.JTextField();
        jbtn_agregar = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jmni_salir = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sie_invdis.Sie_invdisApp.class).getContext().getResourceMap(insumos_entradas_agregar.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jpn_encabezado.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jpn_encabezado.border.title"))); // NOI18N
        jpn_encabezado.setName("jpn_encabezado"); // NOI18N

        jcbx_tiposinsumos.setFont(resourceMap.getFont("jcbx_tiposinsumos.font")); // NOI18N
        jcbx_tiposinsumos.setName("jcbx_tiposinsumos"); // NOI18N
        jcbx_tiposinsumos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbx_tiposinsumosActionPerformed(evt);
            }
        });

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jtf_observaciones.setName("jtf_observaciones"); // NOI18N
        jtf_observaciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_observacionesActionPerformed(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jdc_fechadocto.setDateFormatString(resourceMap.getString("jdc_fechadocto.dateFormatString")); // NOI18N
        jdc_fechadocto.setName("jdc_fechadocto"); // NOI18N

        jcmbx_tiendaclie.setName("jcmbx_tiendaclie"); // NOI18N
        jcmbx_tiendaclie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmbx_tiendaclieActionPerformed(evt);
            }
        });

        jcmbx_almacenes.setName("jcmbx_almacenes"); // NOI18N
        jcmbx_almacenes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmbx_almacenesActionPerformed(evt);
            }
        });

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jcb_verfotos.setText(resourceMap.getString("jcb_verfotos.text")); // NOI18N
        jcb_verfotos.setToolTipText(resourceMap.getString("jcb_verfotos.toolTipText")); // NOI18N
        jcb_verfotos.setName("jcb_verfotos"); // NOI18N
        jcb_verfotos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcb_verfotosActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jtf_docto.setName("jtf_docto"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jtf_descuento.setText(resourceMap.getString("jtf_descuento.text")); // NOI18N
        jtf_descuento.setName("jtf_descuento"); // NOI18N
        jtf_descuento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_descuentoActionPerformed(evt);
            }
        });
        jtf_descuento.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtf_descuentoFocusLost(evt);
            }
        });

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jdc_fecharecepcion.setDateFormatString(resourceMap.getString("jdc_fecharecepcion.dateFormatString")); // NOI18N
        jdc_fecharecepcion.setName("jdc_fecharecepcion"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jtf_impuesto.setText(resourceMap.getString("jtf_impuesto.text")); // NOI18N
        jtf_impuesto.setName("jtf_impuesto"); // NOI18N
        jtf_impuesto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_impuestoActionPerformed(evt);
            }
        });
        jtf_impuesto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtf_impuestoFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jpn_encabezadoLayout = new javax.swing.GroupLayout(jpn_encabezado);
        jpn_encabezado.setLayout(jpn_encabezadoLayout);
        jpn_encabezadoLayout.setHorizontalGroup(
            jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(jtf_observaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jcb_verfotos)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpn_encabezadoLayout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtf_docto, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 83, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jdc_fechadocto, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcmbx_tiendaclie, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(67, 67, 67))
                    .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_descuento, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_impuesto, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jdc_fecharecepcion, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcmbx_almacenes, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbx_tiposinsumos, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jpn_encabezadoLayout.setVerticalGroup(
            jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jtf_docto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2)
                    .addComponent(jdc_fechadocto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jcmbx_tiendaclie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                        .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(jtf_descuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9)
                                    .addComponent(jtf_impuesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(10, 10, 10))
                            .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jdc_fecharecepcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8))
                                .addGap(10, 10, 10)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtf_observaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcb_verfotos)
                            .addComponent(jLabel4))
                        .addGap(41, 41, 41))
                    .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbx_tiposinsumos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)
                            .addComponent(jcmbx_almacenes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addContainerGap())))
        );

        jpn_cuerpo.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jpn_cuerpo.border.title"))); // NOI18N
        jpn_cuerpo.setName("jpn_cuerpo"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtb_insumos.setModel(this.jtable_modelo);
        jtb_insumos.setName("jtb_insumos"); // NOI18N
        jtb_insumos.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jtb_insumosPropertyChange(evt);
            }
        });
        jtb_insumos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtb_insumosKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jtb_insumos);

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jtf_doctosubtotal.setEditable(false);
        jtf_doctosubtotal.setName("jtf_doctosubtotal"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jtf_doctodesc.setEditable(false);
        jtf_doctodesc.setName("jtf_doctodesc"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jtf_doctoimp.setEditable(false);
        jtf_doctoimp.setName("jtf_doctoimp"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jtf_doctototal.setEditable(false);
        jtf_doctototal.setName("jtf_doctototal"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jtf_totalpiezas.setEditable(false);
        jtf_totalpiezas.setText(resourceMap.getString("jtf_totalpiezas.text")); // NOI18N
        jtf_totalpiezas.setName("jtf_totalpiezas"); // NOI18N

        javax.swing.GroupLayout jpn_cuerpoLayout = new javax.swing.GroupLayout(jpn_cuerpo);
        jpn_cuerpo.setLayout(jpn_cuerpoLayout);
        jpn_cuerpoLayout.setHorizontalGroup(
            jpn_cuerpoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpn_cuerpoLayout.createSequentialGroup()
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtf_totalpiezas, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 197, Short.MAX_VALUE)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_doctosubtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_doctodesc, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_doctoimp, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_doctototal, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE)
        );
        jpn_cuerpoLayout.setVerticalGroup(
            jpn_cuerpoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpn_cuerpoLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpn_cuerpoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jtf_doctosubtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jtf_doctodesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jtf_doctoimp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jtf_doctototal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(jtf_totalpiezas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        jbtn_guardar.setIcon(resourceMap.getIcon("jbtn_guardar.icon")); // NOI18N
        jbtn_guardar.setText(resourceMap.getString("jbtn_guardar.text")); // NOI18N
        jbtn_guardar.setName("jbtn_guardar"); // NOI18N
        jbtn_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_guardarActionPerformed(evt);
            }
        });

        jbtn_salir.setIcon(resourceMap.getIcon("jbtn_salir.icon")); // NOI18N
        jbtn_salir.setText(resourceMap.getString("jbtn_salir.text")); // NOI18N
        jbtn_salir.setName("jbtn_salir"); // NOI18N
        jbtn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_salirActionPerformed(evt);
            }
        });

        jbtn_helpayudame.setIcon(resourceMap.getIcon("jbtn_helpayudame.icon")); // NOI18N
        jbtn_helpayudame.setText(resourceMap.getString("jbtn_helpayudame.text")); // NOI18N
        jbtn_helpayudame.setName("jbtn_helpayudame"); // NOI18N
        jbtn_helpayudame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_helpayudameActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(233, 233, 233)
                .addComponent(jbtn_salir)
                .addGap(130, 130, 130)
                .addComponent(jbtn_helpayudame)
                .addContainerGap(283, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jbtn_guardar)
                    .addContainerGap(685, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jbtn_helpayudame)
                .addComponent(jbtn_salir))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(2, 2, 2)
                    .addComponent(jbtn_guardar)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jtf_idinsumo.setName("jtf_idinsumo"); // NOI18N
        jtf_idinsumo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_idinsumoActionPerformed(evt);
            }
        });

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jtf_insumodescripcion.setName("jtf_insumodescripcion"); // NOI18N
        jtf_insumodescripcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_insumodescripcionActionPerformed(evt);
            }
        });

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jtf_item.setName("jtf_item"); // NOI18N
        jtf_item.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_itemActionPerformed(evt);
            }
        });

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jtf_unidadsal.setText(resourceMap.getString("jtf_unidadsal.text")); // NOI18N
        jtf_unidadsal.setName("jtf_unidadsal"); // NOI18N
        jtf_unidadsal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_unidadsalActionPerformed(evt);
            }
        });

        jbtn_agregar.setIcon(resourceMap.getIcon("jbtn_agregar.icon")); // NOI18N
        jbtn_agregar.setText(resourceMap.getString("jbtn_agregar.text")); // NOI18N
        jbtn_agregar.setName("jbtn_agregar"); // NOI18N
        jbtn_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_agregarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_idinsumo, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_insumodescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_item, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtf_unidadsal, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                .addComponent(jbtn_agregar)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel14)
                .addComponent(jtf_idinsumo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel15)
                .addComponent(jtf_insumodescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel16)
                .addComponent(jtf_item, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel17)
                .addComponent(jtf_unidadsal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jbtn_agregar)
        );

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jmni_salir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        jmni_salir.setIcon(resourceMap.getIcon("jmni_salir.icon")); // NOI18N
        jmni_salir.setText(resourceMap.getString("jmni_salir.text")); // NOI18N
        jmni_salir.setName("jmni_salir"); // NOI18N
        jmni_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_salirActionPerformed(evt);
            }
        });
        jMenu1.add(jmni_salir);

        jMenuBar1.add(jMenu1);

        jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
        jMenu2.setName("jMenu2"); // NOI18N

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        jMenu3.setText(resourceMap.getString("jMenu3.text")); // NOI18N
        jMenu3.setName("jMenu3"); // NOI18N
        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpn_cuerpo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpn_encabezado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jpn_encabezado, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpn_cuerpo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcbx_tiposinsumosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbx_tiposinsumosActionPerformed
        // TODO add your handling code here:


        if  ( controlcombo > 0)  {
            if(JOptionPane.showConfirmDialog(null, "Estan Correctos sus Datos?")==0) {
                String arreglo_tipoinsumos[]=null;
                arreglo_tipoinsumos=this.jcbx_tiposinsumos.getSelectedItem().toString().split(":");
                this.cargar_insumos(Integer.valueOf(arreglo_tipoinsumos[0]));
                this.jtf_observaciones.requestFocus();
            }

        } else {

        }
}//GEN-LAST:event_jcbx_tiposinsumosActionPerformed

    private void jcb_verfotosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcb_verfotosActionPerformed
        // TODO add your handling code here:
        if(this.jcb_verfotos.isSelected()==true) {
            //this.verfotosestereporte();
        } else {
            //this.quitarfotosestereporte();
        }
}//GEN-LAST:event_jcb_verfotosActionPerformed

    private void jtf_descuentoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtf_descuentoFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_jtf_descuentoFocusLost

    private void jtf_impuestoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtf_impuestoFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_jtf_impuestoFocusLost

    private void jmni_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_salirActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jmni_salirActionPerformed

    private void jtb_insumosPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jtb_insumosPropertyChange
        // TODO add your handling code here:
        this.calcularimportes();
}//GEN-LAST:event_jtb_insumosPropertyChange

    private void jtb_insumosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtb_insumosKeyPressed
        // TODO add your handling code here:
        System.out.println(evt.getKeyCode());
        System.out.println("Hola");
        if (evt.getKeyCode() == 10) {
            try {
                this.calcularimportes();
            } catch (Exception ex) {
                System.out.println("ERROR no ha elegido en el cuadro de texto");
            }

        }
    }//GEN-LAST:event_jtb_insumosKeyPressed

    private void jbtn_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_guardarActionPerformed
        // TODO add your handling code here:
        float tpiezas=Float.valueOf(this.jtf_totalpiezas.getText().trim());
        int index=this.jcmbx_tiendaclie.getSelectedIndex();
        if ((this.jtf_docto.getText().toString().length()>0) && (index>0)  && (tpiezas>0))
            {
                this.documento_guardar();
                System.out.println("se guarda");
            }
        else
            {
                JOptionPane.showMessageDialog(null,"Favor de Verificar Folio Documento y Proveedor", "Sistema Integral(Agregar Articulo) : Error",1);
            }

}//GEN-LAST:event_jbtn_guardarActionPerformed

    private void jbtn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_salirActionPerformed
        // TODO add your handling code here:
        //x.cierraConexion();
        this.dispose();
}//GEN-LAST:event_jbtn_salirActionPerformed

    private void jbtn_helpayudameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_helpayudameActionPerformed
        // TODO add your handling code here:
        //  this.ayuda();
}//GEN-LAST:event_jbtn_helpayudameActionPerformed

    private void jbtn_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_agregarActionPerformed
        // TODO add your handling code here:
        
        if ((this.jtf_idinsumo.getText().toString().length()>0) && (this.jtf_insumodescripcion.getText().toString().length()>0) && (this.jtf_item.getText().toString().length()>0) && (this.jtf_unidadsal.getText().toString().length()>0))
            {
                this.articulo_agregar();
            }
        else
            {
            JOptionPane.showMessageDialog(null,"Favor de Verificar los campos antes de Agregar el Articulo", "Sistema Integral(Agregar Articulo) : Error",1);
                
            }
    }//GEN-LAST:event_jbtn_agregarActionPerformed

private void articulo_agregar()
    {
    if(JOptionPane.showConfirmDialog(null, "Desea Agregar este Articulo?")==0)
         {
             String arreglo_tipoinsumos[]=null;
             arreglo_tipoinsumos=this.jcbx_tiposinsumos.getSelectedItem().toString().split(":");
             if(arreglo_tipoinsumos[0].equals("0"))
                    {
                           System.out.println("error elija un tipo de Insumo");
                          JOptionPane.showMessageDialog(null,"error elija un tipo de Insumo", "Sistema Integral(Agregar Articulo) : Error",1);
                    }
             else
                   {
                    int controlfolio=0;
                    String texto="select * from x1distribucion_insumos_articulos_insert('"+this.jtf_idinsumo.getText().trim().toUpperCase()+"','',1,'"+this.jtf_insumodescripcion.getText().trim().toUpperCase().replace(",", "").replace("{", "").replace("}", "")+"','"+this.jtf_item.getText().trim().toUpperCase()+"','"+this.jtf_unidadsal.getText().trim().toUpperCase()+"','"+this.jtf_unidadsal.getText().trim().toUpperCase()+"',1,'',"+arreglo_tipoinsumos[0]+",'','','',0,0,0,0,0,0,0,'',0,0,'','','') as (idinsumo character varying(16),descripcion character varying(80),item character varying(16),unidad character varying(3));";

                    System.out.println(texto);


                    try {
                        rs = x.sieuno_executediversosv2(texto,variables_global.getconexiongral());
                        while (rs.next())
                            {
                                    controlfolio=1;
                                    JOptionPane.showMessageDialog(null,"Articulo Agregado Correctamente", "Sistema Integral(Agregar Articulo) : Confirmacion",1);
                                    jtable_modelo.addRow(new Object[]{rs.getString("idinsumo"),rs.getString ("descripcion"),rs.getString ("unidad"),0,0,this.jtf_descuento.getText().trim(),this.jtf_impuesto.getText().trim(),0,"."});
                                    this.jtf_idinsumo.setText("");
                                    this.jtf_insumodescripcion.setText("");
                                    this.jtf_unidadsal.setText("");
                                    this.jtf_item.setText("");
                                    this.jtf_descuento.setText("");
                                    this.jtf_impuesto.setText("");
                            }
                    } catch(Exception e)
                        {
                              System.out.println(e.getMessage());
                              JOptionPane.showMessageDialog(null,"Error conexion", "Sistema Integral(Integral) : Error",1);
                        }
                    if (controlfolio == 0 )
                            {
                                        JOptionPane.showMessageDialog(null,"Error Verifique Articulo", "Sistema Integral(Agregar Insumo) : Error",1);
                            }


                 }

        }
    }

private void articulo_busqueda()
    {
        String texto="select * from x1distribucion_insumos_articulos_entradabusqueda('"+this.jtf_idinsumo.getText().trim().toUpperCase()+"') as (idinsumo character varying(16),descripcion character varying(80),item character varying(16),unidad character varying(3));";
        System.out.println(texto);


                    try {
                        rs = x.sieuno_executediversosv2(texto,variables_global.getconexiongral());
                        while (rs.next())
                            {
                               this.jtf_idinsumo.setText(rs.getString("idinsumo"));
                               this.jtf_insumodescripcion.setText(rs.getString("descripcion"));
                               this.jtf_item.setText(rs.getString("item"));
                               this.jtf_unidadsal.setText(rs.getString("unidad"));
                            }
                    } catch(Exception e)
                        {
                              System.out.println(e.getMessage());
                              JOptionPane.showMessageDialog(null,"Error conexion", "Sistema Integral(Integral) : Error",1);
                        }
    }

private void documento_guardar()
    {
        ResultSet rs = null;
        float cantidad=0;
        int nobjetotabla=this.jtb_insumos.getRowCount();
        int fi=0,controlfolio=0;
        String cadenafilas="{'", arreglo_articulos[]=null;
        JPasswordField pwd = new JPasswordField(10);
        //this.quitarfotosestereporte();
        //lanso la confirmacion de password
        int action = JOptionPane.showConfirmDialog(null, pwd,"Contraseña:(Use Tab p/moverse o Mause)",JOptionPane.OK_CANCEL_OPTION);
        if(action < 0) {
            JOptionPane.showMessageDialog(null,"No se realiza Proceso, Gracias");
        } else {
            //comparo si la contraseña es apropiada
            if(variables_global.getPassword().equals(String.valueOf(pwd.getPassword()))) {//inicia trabajo para actualizar diferencias


                for(fi=0;fi<nobjetotabla;fi++)
                {
                    try {
                        cantidad = Float.valueOf(this.jtb_insumos.getValueAt(fi, 3).toString()).floatValue();
                    } catch (NumberFormatException nfe) {
                        cantidad=0;
                    }
                    // System.out.println("cachar error"+cadenafilas);
                    if (cantidad > 0) {
                        cadenafilas+=""+this.jtb_insumos.getValueAt(fi, 3).toString()+":"+this.jtb_insumos.getValueAt(fi, 0).toString()+":"+this.jtb_insumos.getValueAt(fi, 4)+""+"\n";
                    }
                }//fin del for

                //System.out.println(s);
                //arreglo_articulos=cadenafilas.split(":");

                if(JOptionPane.showConfirmDialog(null, "Documento sera Guardado. Estan correcto sus Datos?")==0)
                    {

                    //this.quitardescripcion();
                    java.util.Vector arreglodearticulos=this.jtable_modelo.getDataVector();

                    String articulos_papostgresql=arreglodearticulos.toString();
                    articulos_papostgresql=articulos_papostgresql.replace('[','{');
                    articulos_papostgresql=articulos_papostgresql.replace(']','}');
                    articulos_papostgresql=articulos_papostgresql.replace("null",".");


                    String arreglo_clie[]=this.jcmbx_tiendaclie.getSelectedItem().toString().split(":");
                    //String arreglo_depa[]=this.jcmbx_depa.getSelectedItem().toString().split(":");
                    String arreglo_alma[]=this.jcmbx_almacenes.getSelectedItem().toString().split(":");
                    String arreglo_tipoinsu[]=this.jcbx_tiposinsumos.getSelectedItem().toString().split(":");

                    String texto="select * from x1distribucion_insumos_entradas_insert('"+arreglo_clie[0]+"','"+this.jtf_docto.getText().trim()+"','"+this.fechaamericana(this.jdc_fechadocto.getDate())+"','"+this.fechaamericana(this.jdc_fecharecepcion.getDate())+"',"+Float.valueOf(this.jtf_descuento.getText().trim())+","+Float.valueOf(this.jtf_impuesto.getText().trim())+",'"+this.jtf_observaciones.getText()+"','',"+Integer.valueOf(arreglo_alma[0])+",'"+articulos_papostgresql+"')";
                    System.out.println(texto);
                    rs=x.sieuno_executediversosv2(texto,variables_global.getconexiongral());
                    try {
                        while (rs.next()) {
                            controlfolio=rs.getInt(1);
                            if (rs.getInt(1) > 0) {
                                JOptionPane.showMessageDialog(null,"Requisicion Correcta, Gracias", "Sistema Integral(Requisicion Insumos) : Confirmacion",1);
                                // this.imprimir(1,1,controlfolio);

                            } else {
                                JOptionPane.showMessageDialog(null," Error Verifique sus Cantidades", "Sistema Integral(requisicion Insumos) : Error",1);
                            }
                        }

                    } catch(Exception e) {
                        System.out.println(e.getMessage());
                        JOptionPane.showMessageDialog(null," Recepcion Incorrecta ", "Sistema Integral(Requisicion Insumos) : Error",1);
                    }


                    //this.btn_guardar.setVisible(false);
                }//fin del if qu confirmo guardar diferencia

            } else {
                JOptionPane.showMessageDialog(null,"por Favor teclee su contraseña coreectamente, verifique mayusculas en teclado");
            }

        }
    }


    private void jtf_descuentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_descuentoActionPerformed
        // TODO add your handling code here:
        this.jtf_impuesto.requestFocus();
    }//GEN-LAST:event_jtf_descuentoActionPerformed

    private void jtf_impuestoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_impuestoActionPerformed
        // TODO add your handling code here:
        this.jdc_fecharecepcion.requestFocus();
    }//GEN-LAST:event_jtf_impuestoActionPerformed

    private void jtf_observacionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_observacionesActionPerformed
        // TODO add your handling code here:
        this.jtf_idinsumo.requestFocus();
    }//GEN-LAST:event_jtf_observacionesActionPerformed

    private void jtf_idinsumoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_idinsumoActionPerformed
        // TODO add your handling code here:

        this.jtf_insumodescripcion.requestFocus();

        this.articulo_busqueda();

    }//GEN-LAST:event_jtf_idinsumoActionPerformed

    private void jtf_insumodescripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_insumodescripcionActionPerformed
        // TODO add your handling code here:
        this.jtf_item.requestFocus();
    }//GEN-LAST:event_jtf_insumodescripcionActionPerformed

    private void jtf_itemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_itemActionPerformed
        // TODO add your handling code here:
        this.jtf_unidadsal.requestFocus();
    }//GEN-LAST:event_jtf_itemActionPerformed

    private void jtf_unidadsalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_unidadsalActionPerformed
        // TODO add your handling code here:
        this.jbtn_agregar.requestFocus();
    }//GEN-LAST:event_jtf_unidadsalActionPerformed

    private void jcmbx_tiendaclieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmbx_tiendaclieActionPerformed
        // TODO add your handling code here:
        this.jtf_descuento.requestFocus();
        
    }//GEN-LAST:event_jcmbx_tiendaclieActionPerformed

    private void jcmbx_almacenesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmbx_almacenesActionPerformed
        // TODO add your handling code here:
        this.jcbx_tiposinsumos.requestFocus();
    }//GEN-LAST:event_jcmbx_almacenesActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        this.jmni_salirActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem1ActionPerformed
 private String fechaamericana(Date fe) {
       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("yyyy-MM-dd");
       String cadenafecha="";
       cadenafecha= formateadorestaeuropa.format(fe);
       return cadenafecha;
    }

private String  fechaeuropea(Date fecha) {
       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("dd-MM-yyyy");
       String cadenafecha="";
       cadenafecha= formateadorestaeuropa.format(fecha);
       return cadenafecha;
    }

 private void calcularimportes()
    {
     int numerofilas=this.jtable_modelo.getRowCount(),error=0;
    String punto="",comas="",imagen="";
    float cantidad=0,costo=0,importefila=0,descuento=0,impuesto=0,doctosubtotal=0,doctoimpuesto=0,doctodescuento=0,doctototal=0,piezasindi=0;
     for(int i = 0 ;i < numerofilas; i++)
                {
                 try
                       {
                            cantidad = Float.valueOf(this.jtb_insumos.getValueAt(i, 3).toString()).floatValue();
                            costo = Float.valueOf(this.jtb_insumos.getValueAt(i, 4).toString()).floatValue();
                            piezasindi+=cantidad;
                            descuento=(costo*cantidad)*(Float.valueOf(this.jtf_descuento.getText().toString())/100);
                            System.out.println(descuento);
                            impuesto=Float.valueOf(this.jtf_impuesto.getText().toString())/100;
                            System.out.println(descuento+":"+impuesto);
                            importefila=(cantidad*costo);
                            doctodescuento+=descuento;
                            doctosubtotal+=importefila;

                        }
                            catch (NumberFormatException nfe) {
                            cantidad=0;
                            costo=0;
                            error=1;
                        }
                      jtable_modelo.setValueAt(importefila, i,7);
                }
    doctoimpuesto=(doctosubtotal-doctodescuento)*impuesto;
    doctototal=(doctosubtotal-doctodescuento)+doctoimpuesto;
    this.jtf_doctosubtotal.setText(String.valueOf(doctosubtotal));
    this.jtf_doctodesc.setText(String.valueOf(doctodescuento));
    this.jtf_doctoimp.setText(String.valueOf(doctoimpuesto));
    this.jtf_doctototal.setText(String.valueOf(doctototal));
    this.jtf_totalpiezas.setText(String.valueOf(piezasindi));
    }

   

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                insumos_entradas_agregar dialog = new insumos_entradas_agregar(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtn_agregar;
    private javax.swing.JButton jbtn_guardar;
    private javax.swing.JButton jbtn_helpayudame;
    private javax.swing.JButton jbtn_salir;
    private javax.swing.JCheckBox jcb_verfotos;
    private javax.swing.JComboBox jcbx_tiposinsumos;
    private javax.swing.JComboBox jcmbx_almacenes;
    private javax.swing.JComboBox jcmbx_tiendaclie;
    private com.toedter.calendar.JDateChooser jdc_fechadocto;
    private com.toedter.calendar.JDateChooser jdc_fecharecepcion;
    private javax.swing.JMenuItem jmni_salir;
    private javax.swing.JPanel jpn_cuerpo;
    private javax.swing.JPanel jpn_encabezado;
    private javax.swing.JTable jtb_insumos;
    private javax.swing.JTextField jtf_descuento;
    private javax.swing.JTextField jtf_docto;
    private javax.swing.JTextField jtf_doctodesc;
    private javax.swing.JTextField jtf_doctoimp;
    private javax.swing.JTextField jtf_doctosubtotal;
    private javax.swing.JTextField jtf_doctototal;
    private javax.swing.JTextField jtf_idinsumo;
    private javax.swing.JTextField jtf_impuesto;
    private javax.swing.JTextField jtf_insumodescripcion;
    private javax.swing.JTextField jtf_item;
    private javax.swing.JTextField jtf_observaciones;
    private javax.swing.JTextField jtf_totalpiezas;
    private javax.swing.JTextField jtf_unidadsal;
    // End of variables declaration//GEN-END:variables

}
